/*
 * @Author: huazi 
 * @Date: 2018-03-05 11:28:27 
 * @Last Modified by: huazi
 * @Last Modified time: 2018-03-06 13:21:56
 * ================用户管理控制模块================
 */

const S = require('../models/initdb.js');//sequelize缩写为S
const Op = S.Op;
const md5 = require('md5');
const config = require('../configs');
const createToken = require('../utils/createToken.js');
const moment = require('moment');

class ShopController{
    //查新不同状态商铺列表
	static async shoplist(ctx){
		const type = ctx.query.type;
		
        let result = await S.Shoplist
            .findAll({
                 'where':{
                    classify:type
                }
            })
            .catch(err => {
                ctx.throw(500, '服务器内部错误-查询商铺列表错误！');
            });

        ctx.success({
            msg: '查询成功',
            retCode:1,
            data: result
        })
	}

    //查询商铺具体信息
    static async shopinfo(ctx){
        const id = ctx.query.id;

        let result = await S.Shopinfo
            .findOne({
                 'where':{
                    id:id
                }
            })
            .catch(err => {
                ctx.throw(500, '服务器内部错误-查询商铺信息错误！');
            });

        //处理imgUrls为数组
        result.dataValues.imgUrls = result.dataValues.imgUrls.split('|');

        //处理info信息为数组
        result.dataValues.info = result.dataValues.info.split('|');

         //处理lat_lng信息为数组
        result.dataValues.lat_lng = result.dataValues.lat_lng.split('|');

         ctx.success({
            msg: '查询成功',
            retCode:1,
            data: result
        })
    }
}

exports = module.exports = ShopController;